class TrustedfileController < ApplicationController
  
  def make
    #ucs2=UserConnection.find(:all,:conditions=>["session_id =:session_id and thetime > :time",{:session_id=>params[:identifier],:time=>6.minutes.ago}])
    ucs2=UserConnection.find(:all,:conditions=>["session_id =:session_id ",{:session_id=>params[:identifier]}])
    string=''
    if !(ucs2.nil?) then 
      ucs2.each {|u|u.swarm_id
      	if (params[:port].nil?) then
      		#for older version
		    if u.ip!=request.remote_ip then
			  u.ip=request.remote_ip
		      u.save
		    end
      	else
		  u.update_attributes(:ip=>request.remote_ip,:thetime=>Time.new,:port=>params[:port])
	    end
        uc=UserConnection.find(:all,:conditions=>["swarm_id = :swarm_id and thetime > :thetime ",{:swarm_id=>u.swarm_id,:thetime=>6.minutes.ago}])
        uc.each {|u2|
          string << u2.session_id.to_s+"\\:"+u2.ip+"\\:"+u2.port.gsub(/:/,"\\:")+"\n"
        }
      }
    end
    
    @content=string.chomp
    @content_type='text/plain'
    @response.headers["Content-Type"] = @content_type
    logger.debug("request.remote_ip => "+request.remote_ip+"time=>"+Time.new.to_s+"vincent messege trustedpeers=>\n"+@content+"\n end vicent messege")
    render :layout=>false
  end
end
